import TcpSocket from './TcpSocket';
import Coordtransform from '../../utils/Coordtransform';

const Toc = new TcpSocket(think.config('videoConfig'));

// const nameSpace = think.config('nameSpace');
class CatalogVideo extends think.Service {
    constructor() {
        super();
        Toc.on('catalogs', async (data) => {
            const list = data.list;
            for (let value of list) {
                let lat = value.Lat;
                let lng = value.Lng;
                let type = value.type;
                if (Number(type) !== 2 && lat !== 0) {
                    //离线将wgs84地球坐标做换成百度坐标
                    const points = Coordtransform.wgs84tobd09(lng, lat);
                    value.Lng = points[0];
                    value.Lat = points[1];
                }
                this.db['basic_catalog_video'].upsert(value);

            }
        });
        Toc.on('error', (data) => {
            think.logger.error(data);
        });
    }

    ptzControl(deviceId, cmdType, speed) {
        Toc.ptz(deviceId, cmdType, speed);

    }
}

export default CatalogVideo